home *** CD-ROM | disk | FTP | other *** search
- #define __INSTALLR_H
-
-
- #ifndef __FPATH_H
- #include "fpath.h"
- #endif
- #ifndef __STDIO_H
- #include "stdio.h"
- #endif
- #ifndef __OPRDR_H
- #include "oprdr.h"
- #endif
- #ifndef __STDARG_H
- #include "stdarg.h"
- #endif
- #ifndef __ZIPLDR_H /* use dll and indirect calls for zip */
- #include "zipldr.h" /* so that we don't need those dll if */
- #endif /* we don't actually need them. ditto */
- #ifndef __UNZLDR_H /* for unz */
- #include "unzldr.h"
- #endif
- #ifndef __AWNDOBJ_H
- #include "awndobj.h"
- #endif
- #ifndef __VERSION_H
- #include "version.h"
- #endif
-
-
- class dlgprog;
- class pmconv;
- class simpledde;
- class copyctrller;
- class copymonitor;
-
-
- class installer
- {
- int installaux(abspath &srcpath, varpath &dstpath, int isuninstall, copyctrller &cc, copymonitor &cm);
-
- public:
-
- int ecode; /* error code */
- int isrunpm; /* did we start PM to DDE with? */
- int issupressmsg; /* should error msg be supressed? */
- HWND owner; /* owner of the error msg dlgs */
- HWND ownerold; /* original owner for future restoration */
- pmconv *c; /* conversation with program manager */
- simpledde *d; /* dde wrapper */
- oprdrabs *rdr; /* recorder to record all operations (for uninstall) */
- oprdrabs *rdrold; /* original recorder for future restoration */
-
- installer();
- ~installer();
-
- int mkdir(abspath &dir);
- int deldir(abspath &dir);
- int delfile(abspath &path);
- int renfile(abspath &oldpath, abspath &newpath);
- int getcddrv();
- int getdrvtype(abspath &root);
- int multimkdir(abspath &dir);
- int multideldir(abspath &dir);
- int multimkdiroffile(abspath &path);
- int multidelfilesindir(abspath &dir);
- int install(abspath &srcpath, abspath &dstpath);
- int install(abspath &srcpath, abspath &dstpath, copymonitor &cm);
- int install(abspath &srcpath, varpath &dstpath, int isuninstall, copyctrller &cc, copymonitor &cm);
- int setfileattrib(abspath &path, DWORD newflags);
- int getfreespace(abspath &root, DWORD *f);
- int getfreespace(abspath &root, double *f);
- int chkfreespace(abspath &root, double minf);
- int begddepm();
- int runpm();
- int endpm();
- int assertinddepm();
- int addgrup(char grup[]);
- int delgrup(char grup[]);
- int additem(char grup[], char item[], char cmdl[], char icon[] = "", int iidx = 0, char dirw[] = "");
- int additem(char grup[], pmiteminfo &pmii);
- int delitem(char grup[], char item[]);
- int chkgrupoccupied(char grup[]);
- int addregkey(int kroot, char kpath[]);
- int delregkey(int kroot, char kpath[]);
- int getregszv(int kroot, char kpath[], char field[], char value[]);
- int setregfield(int kroot, char kpath[], char field[], DWORD vtype, DWORD vsize, BYTE value[]);
- int getnofields(int kroot, char kpath[]);
- int getnosubkeys(int kroot, char kpath[]);
- int chkexistregkey(int kroot, char kpath[]);
- int chkregkeyoccupied(int kroot, char kpath[]);
- int delregfield(int kroot, char kpath[], char field[]);
- int delregfields(int kroot, char kpath[]);
- int delregsubkeys(int kroot, char kpath[]);
- int ini2reg (abspath &file, char sect[], char entry[], int *kr, char kp[]);
- int delinisect (abspath &file, char sect[]);
- int addinisect (abspath &file, char sect[]);
- int addinientry (abspath &file, char sect[], char entry[], char value[]);
- int delinientry (abspath &file, char sect[], char entry[], int seqno = 0);
- int insinientry (abspath &file, char sect[], char entry[], char value[], int seqno = 0);
- int setinivalue (abspath &file, char sect[], char entry[], char value[], int seqno = 0);
- int setinivaluesimple(abspath &file, char sect[], char entry[], char value[]);
- int installfont(abspath &path, int isuninstall);
- HKEY getregroot(int kroot);
- HWND findpmmainwnd();
- void endddepm(int isendpm);
- void setrdr();
- void setrdr(oprdrabs &rdr);
- void setowner();
- void setowner(HWND owner);
- void error(char msg[], ...);
- void errorvar(char msg[], va_list args);
- void errordel(abspath &path);
- void errorren(abspath &oldpath, abspath &newpath);
- void errormem();
- void erroropen(abspath &path);
- void errorread(abspath &path);
- void errorcopy(abspath &srcpath, abspath &dstpath);
- void errorclose(abspath &path);
- void errormkdir(abspath &dir);
- void errorwrite(abspath &path);
- void errorcreate(abspath &path);
- void errornofile(abspath &path);
- void errorbadpath(abspath &path);
- void erroropenregkey(int kroot, char kpath[]);
- BYTE *getregvalue(int kroot, char kpath[], char field[], DWORD *vtype, DWORD *vsize);
-
- #ifdef WIN32
- char *getdllcountpath();
- DWORD incdllcount(abspath &path);
- DWORD decdllcount(abspath &path);
- DWORD getdllcount(abspath &path);
- DWORD setdllcount(abspath &path, DWORD n);
- #endif
-
- enum /* error code */
- {
- enul, egeneric, edel, eren,
- emem, eopen, eread, ecopy,
- eclose, emkdir, ewrite, ecreate,
- enofile, ebadpath
- };
-
- static oprdrnul rdrnul;
- };
-
- class copymonitor /* copy monitor */
- {
- public:
-
- virtual int notifyread(LONG nobytesread) = 0;
- virtual void notifybeg() = 0;
- virtual void notifyend() = 0;
- virtual UINT getblksize() = 0;
- };
-
- class copymonitorprog:public copymonitor /* copy monitor with progress dlg */
- {
- long sofarfile;
- long totalfile;
- double sofar;
- double total;
- dlgprog &d;
-
- public:
-
- copymonitorprog(dlgprog &dx, double totalx):d(dx)
- {
- total = totalx;
- sofar = 0;
- sofarfile = 0;
- totalfile = 0;
- }
- void notifybeg()
- {
- sofarfile = 0;
- }
- void notifyend()
- {
- notifyread(totalfile-sofarfile); /* in case we skip a part of the file */
- }
- void setsize(long l)
- {
- totalfile = l;
- }
- void undo(long l)
- {
- sofar -= l;
- }
- UINT getblksize()
- {
- return 2048;
- }
- int notifyread(LONG nobytesread);
- };
-
- class copymonitorvoid:public copymonitor /* copy monitor which does nothing */
- {
- int *isabort;
-
- public:
-
- copymonitorvoid(int *isabortx = 0)
- {
- isabort = isabortx;
- }
- int notifyread(LONG nobytesread)
- {
- abswndobj::peekdispatchmsg(1);
-
- return isabort != 0 ? !(*isabort) : 1;
- }
- void notifybeg()
- {
-
- }
- void notifyend()
- {
-
- }
- UINT getblksize()
- {
- return 0; /* return 0 means as large a block as possible */
- }
- };
-
- class cccmp /* how to compare two files */
- {
- public:
-
- /* the file (if existed) has been replaced */
- virtual void done()
- {
-
- }
- /* decompress the file first? */
- virtual int chkdecm1st()
- {
- return 0; /* usually there is no need to decompress it first */
- }
- /* return:0 -- copy 1 -- skip 2 -- error */
- virtual int compare(abspath &srcpath, varpath &dstpath) = 0;
- };
-
- class cccmpver: public cccmp /* version statement comparison */
- {
- public:
-
- HWND owner;
-
- /* decomrpess the file first? */
- int chkdecm1st()
- {
- return 1; /* can't retrieve version statement until it's decompressed */
- }
- /* return:0 -- copy 1 -- skip 2 -- error */
- int compare(abspath &srcpath, varpath &dstpath)
- {
- return version::compare(owner, srcpath, dstpath);
- }
- };
-
- class cccmpini: public cccmp /* ini version comparison */
- {
- stcpath dstpath; /* we'll save version # for this file in done() */
-
- public:
-
- DWORD verhi32; /* high 32 bit of version # */
- DWORD verlo32; /* low 32 bit of version # */
- stcpath inipath; /* path to the INI file */
-
- int compare(abspath &srcpath, varpath &dstpath);
-
- void done();
- };
-
- class cccmptime: public cccmp /* time stamp comparison */
- {
- public:
-
- int compare(abspath &srcpath, varpath &dstpath);
- };
-
- class cccmpsz: public cccmp /* file size comparison */
- {
- public:
-
- long srcl;
-
- int compare(abspath &srcpath, varpath &dstpath);
- };
-
- class cccmpnone: public cccmp /* no comparison at all */
- {
- public:
-
- /* return:0 -- copy 1 -- skip 2 -- error */
- int compare(abspath &/*srcpath*/, varpath &/*dstpath*/)
- {
- return 0;
- }
- };
-
-
- class ccread /* how to read source file */
- {
- public:
-
- /* return:true -- ok false -- error */
- virtual int opensrc(abspath &srcpath) = 0;
-
- /* return:true -- ok false -- error */
- virtual int closesrc() = 0;
-
- /* return:no of bytes read -- ok -1 -- fail */
- virtual UINT getsrc(char b[], UINT n) = 0;
- };
-
- class ccrdnorm: public ccread /* read normal file */
- {
- HFILE h;
-
- public:
-
- /* return:true -- ok false -- error */
- int opensrc(abspath &srcpath)
- {
- OFSTRUCT ofs;
-
- return (h = OpenFile(srcpath, &ofs, OF_READ)) != -1;
- }
- /* return:true -- ok false -- error */
- int closesrc()
- {
- return _lclose(h) != -1;
- }
- /* return:no of bytes read -- ok -1 -- fail */
- UINT getsrc(char b[], UINT n)
- {
- return _lread(h, b, n);
- }
- };
-
- class ccrdcomp: public ccread /* read compressed file */
- {
- int isopen; /* did we open the file? */
-
- lzpunzldr ul; /* used to load lzpunz.dll */
-
- public:
-
- /* return:no of bytes read -- ok -1 -- fail */
- UINT getsrc(char b[], UINT n)
- {
- return ul.LzpUnzRead(b, n);
- }
- int opensrc(abspath &srcpath);
- int closesrc();
- };
-
- class ccwrite /* how to write to a file */
- {
- public:
-
- /* return:true -- ok false -- error */
- virtual int opendst(abspath &dstpath) = 0;
-
- /* return:true -- ok false -- error */
- virtual int closedst() = 0;
-
- /* return:true -- appending false -- creating */
- virtual int chkappend()
- {
- return 0; /* usually we create instead of append */
- }
- /* return:no of bytes written -- ok -1 -- fail */
- virtual UINT putdst(char b[], UINT n) = 0;
-
- /* log down the changes */
- virtual void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall) = 0;
- };
-
- class ccwrnorm: public ccwrite /* write to a normal file */
- {
- HFILE h;
-
- public:
-
- /* return:true -- ok false -- error */
- int opendst(abspath &dstpath)
- {
- OFSTRUCT ofs;
-
- return (h = OpenFile(dstpath, &ofs, OF_CREATE)) != -1;
- }
- /* return:true -- ok false -- error */
- int closedst()
- {
- return _lclose(h) != -1;
- }
- /* return:no of bytes written -- ok -1 -- fail */
- UINT putdst(char b[], UINT n)
- {
- return _lwrite(h, b, n);
- }
- void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
- {
- rdr.instcreatefile(srcpath, dstpath, isuninstall);
- }
- };
-
- class ccwrnormapp: public ccwrite /* append to a normal file */
- {
- int isappend; /* did the file exist when we appended to it? */
- HFILE h;
- DWORD l; /* size of the original file */
-
- public:
-
- /* return:true -- ok false -- error */
- int closedst()
- {
- return _lclose(h) != -1;
- }
- /* return:true -- appending false -- creating */
- int chkappend()
- {
- return 1;
- }
- /* return:no of bytes written -- ok -1 -- fail */
- UINT putdst(char b[], UINT n)
- {
- return _lwrite(h, b, n);
- }
- int opendst(abspath &dstpath);
-
- void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall);
- };
-
- class ccwrcomp: public ccwrite /* write to a compressed file */
- {
- int iscreated;
-
- lzpzipldr zl; /* used to load lzpzip.dll */
-
- public:
-
- /* return:true -- ok false -- error */
- void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
- {
- rdr.instcreatefile(srcpath, dstpath, isuninstall);
- }
- /* return:no of bytes written -- ok -1 -- fail */
- UINT putdst(char b[], UINT n)
- {
- return zl.LzpZipWrite(b, n);
- }
- int opendst(abspath &dstpath);
- int closedst();
- };
-
- class copyctrller
- {
- public:
-
- int issametime; /* keep time stamp? */
- cccmp *cmp; /* how to compare the two files */
- ccread *rd; /* how to read the source file */
- ccwrite *wr; /* how to write the target file */
-
- copyctrller()
- {
- issametime = 0; /* no, just use the time of creation */
- cmp = 0;
- rd = 0;
- wr = 0;
- }
- int chkdecm1st()
- {
- return cmp->chkdecm1st();
- }
- int chkappend()
- {
- return wr->chkappend();
- }
- /* return:0 -- copy 1 -- skip 2 -- error */
- int compare(abspath &srcpath, varpath &dstpath)
- {
- return cmp->compare(srcpath, dstpath);
- }
- /* return:true -- ok false -- error */
- int opensrc(abspath &srcpath)
- {
- return rd->opensrc(srcpath);
- }
- /* return:true -- ok false -- error */
- int opendst(abspath &dstpath)
- {
- return wr->opendst(dstpath);
- }
- /* return:true -- ok false -- error */
- int closesrc()
- {
- return rd->closesrc();
- }
- /* return:true -- ok false -- error */
- int closedst()
- {
- return wr->closedst();
- }
- /* return:no of bytes read -- ok -1 -- fail */
- UINT getsrc(char b[], UINT n)
- {
- return rd->getsrc(b, n);
- }
- /* return:no of bytes written -- ok -1 -- fail */
- UINT putdst(char b[], UINT n)
- {
- return wr->putdst(b, n);
- }
- void done()
- {
- cmp->done();
- }
- void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
- {
- wr->record(rdr, srcpath, dstpath, isuninstall);
- }
- };
-
- class pmddekeeper
- {
- int isendpm;
-
- installer &ir;
-
- public:
-
- pmddekeeper(installer &ir_):ir(ir_)
- {
- isendpm = 1;
-
- ir.begddepm();
- }
- pmddekeeper(int *r, installer &ir_, int isendpm_):ir(ir_)
- {
- isendpm = isendpm_;
-
- *r = ir.begddepm(); /* begin DDE */
- }
- ~pmddekeeper()
- {
- ir.endddepm(isendpm);
- }
- };
-